<template>
  <div class="common-page">
    <SearchForm
      :search-list="searchList"
      :search-params="searchParams"
      @search="onSearch"
      @reset="onReset"
    />
    <div class="table-box">
      <el-table
        v-loading="loading"
        height="100%"
        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >
        <el-table-column v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label" align="center" />
        <el-table-column label="操作" fixed="right" width="160px">
          <template slot-scope="scope">
            <el-button type="primary" @click="onCloud(scope.row)">云上联审</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        @size-change="changePageSize"
        @current-change="changePageNo"
      />
    </div>
    <Add ref="addFormRef" />
    <el-dialog
      title="云上联审"
      :visible.sync="dialogValue"
      width="500px"
      append-to-body
    >
      <SubmitForm
        :rule-form="ruleForm"
        :rules="rules"
        :form-list="formList"
        @close="dialogValue = false"
        @save="onSave"
      />
    </el-dialog>

  </div>
</template>

<script>
import crud from '@/mixins/crud'
import { http } from '@/api'
import {Investor, ProjectType, getName, MeetingType} from '@/dict'
export default {
  name: 'Index',
  mixins: [crud],
  data() {
    return {
      request: http.project_center,
      searchList: [
        {
          key: 'projectType',
          name: 'select',
          label: '项目类型',
          options: ProjectType
        },
        {
          key: 'meetingType',
          name: 'select',
          label: '会议类别',
          options: MeetingType
        },
        {
          key: 'projectName',
          name: 'input',
          label: '项目名称'
        },
        {
          key: 'timeValue',
          name: 'datetime',
          valueFormat: 'yyyy-MM-dd',
          dateType: 'daterange',
          label: '时间'
        }
      ],
      searchParams: {
        projectType: '',
        investor: '',
        projectName: '',
        timeValue: []
      },
      columns: [
        { prop: 'projectName', label: '项目名称' },
        { prop: 'meetingTypeName', label: '会议类别' },
        { prop: 'investorName', label: '组织单位' },
        { prop: 'createTime', label: '评审申报时间' }
      ],
      tableData: [

      ],
      ruleForm: {
        url: '',
      },
      rules: {
        url: [{ required: true, message: '腾讯会议ID' }]
      },
      formList: [
          {
              key: 'id',
              name: 'select',
              label: '专家',
              colSpan: 24,
              options: [],
              multiple: true
          },
        {
          key: 'url',
          name: 'input',
          label: '腾讯会议ID',
          colSpan: 24
        },
      ]
    }
  },
  methods: {
    formatTableData(data) {
      data.forEach(el => {
        el.projectTypeName = getName(el.projectType, ProjectType)
        el.investorName = getName(el.investor, Investor)
        el.meetingTypeName = getName(el.meetingType, MeetingType)
      })
    },
    onRead(item) {
      this.$refs.addFormRef.open(item)
    },
    onCloud(row) {
        http.project_center.getids({
            projectId:row.id
        }).then(res => {
            this.formList[0].options = res.data.records.map(el => {
                return {
                    value: el.id,
                    name: el.expertName
                }
            })
        })
      this.currentDetail = row
      this.dialogValue = true
    },
    onSave() {
        http.project_center.sendCloud({
            ids: this.ruleForm.id,
            url: this.ruleForm.url
        }).then(res => {
            this.$message.success(res.msg)
            this.ruleForm = {
                url: '',
                id: []
            }
            this.dialogValue = false
            this.initData()
        })
    }
  }
}
</script>

<style scoped lang="scss">
</style>
